<template>
  <div class="ai-agent-container">
    <!-- 通知提示 -->
    <div class="ai-notification" v-if="notification">
      {{ notification }}
    </div>

    <!-- AI智能体悬浮按钮 -->
    <div 
      v-if="!isExpanded" 
      class="ai-agent-button" 
      @click="toggleExpanded"
      :class="{ 'pulse-animation': showPulse }"
    >
      <div class="ai-avatar">
        <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
          <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-13h2v6h-2zm0 8h2v2h-2z"/>
        </svg>
      </div>
    </div>

    <!-- AI智能体对话框 -->
    <div v-if="isExpanded" class="ai-agent-dialog">
      <!-- 对话框头部 -->
      <div class="dialog-header">
        <div class="ai-info">
          <div class="ai-avatar large">
            <svg width="32" height="32" viewBox="0 0 24 24" fill="currentColor">
              <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-13h2v6h-2zm0 8h2v2h-2z"/>
            </svg>
          </div>
          <div class="ai-name">AI助手</div>
        </div>
        <div class="dialog-controls">
          <button class="control-btn minimize-btn" @click="minimizeDialog">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
              <path d="M5 15h14v2H5z"/>
            </svg>
          </button>
          <button class="control-btn close-btn" @click="closeDialog">
            <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
              <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
            </svg>
          </button>
        </div>
      </div>

      <!-- 对话框内容区域 -->
      <div class="dialog-content">
        <div v-if="messages.length === 0" class="welcome-message">
          <p>👋 你好！我是B站AI助手小站，很高兴为你服务。</p>
          <p class="hint">我可以帮你：</p>
          <ul>
            <li>推荐你喜欢的视频内容</li>
            <li>定制个性化内容</li>
            <li>生成创意视频建议</li>
            <li>回答关于B站的问题</li>
          </ul>
        </div>
        
        <div v-else class="message-list">
          <div 
            v-for="(message, index) in messages" 
            :key="index"
            :class="['message-item', message.sender === 'user' ? 'user-message' : 'ai-message']"
          >
            <div v-if="message.sender === 'user'" class="user-avatar"></div>
            <div class="message-content" :class="{ 'ai-content': message.sender === 'ai' }">
              <p>{{ message.text }}</p>
              <div v-if="message.sender === 'ai' && message.quickActions" class="quick-actions">
                <button 
                  v-for="(action, actionIndex) in message.quickActions" 
                  :key="actionIndex"
                  class="quick-action-btn"
                  @click="handleQuickAction(action)"
                >
                  {{ action }}
                </button>
              </div>
            </div>
          </div>
          
          <!-- 打字状态指示器 -->
          <div v-if="isTyping" class="message-item ai-message">
            <div class="ai-avatar small">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
                <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-13h2v6h-2zm0 8h2v2h-2z"/>
              </svg>
            </div>
            <div class="message-content ai-content typing-indicator">
              <span class="typing-dot"></span>
              <span class="typing-dot"></span>
              <span class="typing-dot"></span>
            </div>
          </div>
          
          <!-- 推荐内容预览 -->
          <div v-if="contentRecommendations.length > 0" class="recommendations-preview">
            <h5>为你推荐</h5>
            <div class="recommendation-items">
              <div 
                v-for="(item, index) in contentRecommendations.slice(0, 3)" 
                :key="index"
                class="recommendation-item"
              >
                <div class="rec-thumbnail"></div>
                <div class="rec-info">
                  <div class="rec-title">{{ item.title }}</div>
                  <div class="rec-meta">
                    <span class="rec-author">{{ item.author }}</span>
                    <span class="rec-stats">{{ item.views }}次观看</span>
                  </div>
                </div>
              </div>
            </div>
            <button 
              class="view-more-btn" 
              @click="switchTab('customize')"
            >
              查看更多推荐 →
            </button>
          </div>
        </div>

        <!-- 功能选择标签页 -->
        <div class="feature-tabs">
          <button 
            v-for="tab in featureTabs" 
            :key="tab.id"
            :class="['tab-btn', { active: activeTab === tab.id }]"
            @click="switchTab(tab.id)"
          >
            {{ tab.name }}
          </button>
        </div>

        <!-- 功能面板 -->
        <div class="feature-panel" v-show="activeTab !== 'chat'">
          <!-- 内容定制面板 -->
          <div v-if="activeTab === 'customize'" class="customize-panel">
            <h4>定制你喜欢的内容</h4>
            <div class="preferences-form">
              <div class="form-group">
                <label>兴趣类别</label>
                <div class="tags-container">
                  <label v-for="category in categories" :key="category" class="tag-checkbox">
                    <input 
                      type="checkbox" 
                      :value="category" 
                      v-model="selectedCategories"
                    />
                    <span class="tag-name">{{ category }}</span>
                  </label>
                </div>
              </div>
              <div class="form-group">
                <label>内容风格</label>
                <select v-model="contentStyle">
                  <option value="全部">全部风格</option>
                  <option value="轻松搞笑">轻松搞笑</option>
                  <option value="知识科普">知识科普</option>
                  <option value="深度解析">深度解析</option>
                  <option value="创意制作">创意制作</option>
                </select>
              </div>
              <div class="form-group">
                <label>视频时长</label>
                <select v-model="videoDuration">
                  <option value="不限">不限</option>
                  <option value="短视频(1-5分钟)">短视频(1-5分钟)</option>
                  <option value="中视频(5-15分钟)">中视频(5-15分钟)</option>
                  <option value="长视频(15分钟以上)">长视频(15分钟以上)</option>
                </select>
              </div>
              <button class="apply-btn" @click="applyPreferences">应用偏好设置</button>
            </div>
            
            <!-- 推荐内容展示 -->
            <div class="recommendations-section" v-if="!isLoadingRecommendations">
              <h5>根据你的偏好推荐</h5>
              <div v-if="contentRecommendations.length > 0" class="recommendation-items">
                <div 
                  v-for="(item, index) in contentRecommendations" 
                  :key="index"
                  class="recommendation-item"
                >
                  <div class="rec-thumbnail"></div>
                  <div class="rec-info">
                    <div class="rec-title">{{ item.title }}</div>
                    <div class="rec-meta">
                      <span class="rec-author">{{ item.author }}</span>
                      <span class="rec-stats">{{ item.views }}次观看</span>
                    </div>
                  </div>
                </div>
              </div>
              <div v-else class="no-recommendations">
                暂无推荐内容，请设置你的偏好
              </div>
            </div>
            <div class="loading-recommendations" v-else>
              <div class="loading-spinner"></div>
              <span>正在加载推荐内容...</span>
            </div>
          </div>

          <!-- 视频生成面板 -->
          <div v-if="activeTab === 'generate'" class="generate-panel">
            <h4>AI视频生成</h4>
            <div class="generate-form">
              <div class="form-group">
                <label>视频主题</label>
                <input 
                  type="text" 
                  v-model="videoTopic" 
                  placeholder="请输入视频主题"
                />
              </div>
              <div class="form-group">
                <label>视频描述</label>
                <textarea 
                  v-model="videoDescription" 
                  placeholder="详细描述你想要的视频内容"
                  rows="3"
                ></textarea>
              </div>
              <div class="form-group">
                <label>视频风格</label>
                <select v-model="generatedVideoStyle">
                  <option value="动画">动画</option>
                  <option value="实拍">实拍</option>
                  <option value="插画">插画</option>
                  <option value="混合">混合</option>
                </select>
              </div>
              <div class="form-group">
                <label>视频长度</label>
                <input 
                  type="range" 
                  v-model="videoLength" 
                  min="30" 
                  max="300" 
                  step="15"
                />
                <span>{{ videoLength }}秒</span>
              </div>
              <button 
                class="generate-btn" 
                @click="generateVideo" 
                :disabled="isGenerating"
              >
                {{ isGenerating ? '生成中...' : '生成视频建议' }}
              </button>
            </div>
            
            <!-- 生成结果 -->
            <div v-if="generatedVideoResult" class="generate-result">
              <div class="result-header">
                <h5>生成结果</h5>
                <button 
                  class="clear-result-btn"
                  @click="clearGenerationResult"
                >
                  清除
                </button>
              </div>
              <div class="result-content">
                <p><strong>视频标题：</strong>{{ generatedVideoResult.title }}</p>
                <p><strong>视频大纲：</strong></p>
                <ul>
                  <li v-for="(point, index) in generatedVideoResult.outline" :key="index">
                    {{ point }}
                  </li>
                </ul>
                <p><strong>素材建议：</strong>{{ generatedVideoResult.materials }}</p>
                <p><strong>参考视频：</strong></p>
                <div class="reference-videos">
                  <div 
                    v-for="(video, index) in generatedVideoResult.references" 
                    :key="index"
                    class="reference-video-item"
                  >
                    <div class="video-thumbnail"></div>
                    <div class="video-info">
                      <div class="video-title">{{ video.title }}</div>
                      <div class="video-author">{{ video.author }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 对话框输入区域 -->
      <div class="dialog-input" v-show="activeTab === 'chat'">
        <input 
          type="text" 
          v-model="inputMessage" 
          placeholder="输入你的问题..."
          @keyup.enter="sendMessage"
          :disabled="isTyping"
        />
        <button class="send-btn" @click="sendMessage" :disabled="!inputMessage.trim() || isTyping">
          <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
            <path d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"/>
          </svg>
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import aiService from '../services/aiService.js';

export default {
  name: 'AIAgent',
  data() {
    return {
      isExpanded: false,
      showPulse: true,
      messages: [],
      inputMessage: '',
      activeTab: 'chat',
      featureTabs: [
        { id: 'chat', name: '对话' },
        { id: 'customize', name: '内容定制' },
        { id: 'generate', name: '视频生成' }
      ],
      // 内容定制相关数据
      categories: ['动画', '游戏', '音乐', '科技', '美食', '生活', '电影', '知识', '娱乐', '体育'],
      selectedCategories: [],
      contentStyle: '全部',
      videoDuration: '不限',
      // 视频生成相关数据
      videoTopic: '',
      videoDescription: '',
      generatedVideoStyle: '动画',
      videoLength: 60,
      isGenerating: false,
      generatedVideoResult: null,
      // 新增的AI服务相关数据
      isTyping: false,
      contentRecommendations: [],
      isLoadingRecommendations: false,
      notification: null
    }
  },
  created() {
    // 初始化时加载用户偏好
    this.loadUserPreferences();
  },
  mounted() {
    // 3秒后停止脉冲动画
    setTimeout(() => {
      this.showPulse = false
    }, 3000)
    
    // 设置AI助手欢迎消息
    this.messages.push({
      sender: 'ai',
      text: '你好！我是B站AI助手小站，很高兴为你服务。我可以为你推荐内容、回答问题，还能帮你生成视频创意！'
    })
  },
  computed: {
    canSend() {
      return this.inputMessage.trim().length > 0 && !this.isTyping;
    }
  },
  methods: {
    toggleExpanded() {
      this.isExpanded = true
    },
    minimizeDialog() {
      this.isExpanded = false
    },
    closeDialog() {
      this.isExpanded = false
      // 重置对话
      this.messages = []
      this.inputMessage = ''
      this.activeTab = 'chat'
    },
    sendMessage() {
      if (!this.inputMessage.trim() || this.isTyping) return
      
      // 添加用户消息
      this.messages.push({
        sender: 'user',
        text: this.inputMessage.trim()
      })
      
      const userMessage = this.inputMessage.trim()
      this.inputMessage = ''
      this.isTyping = true
      
      // 使用AI服务处理消息
      aiService.processMessage(userMessage, {
        categories: this.selectedCategories,
        style: this.contentStyle,
        duration: this.videoDuration
      })
        .then(response => {
          this.messages.push({
            sender: 'ai',
            text: response
          })
          this.isTyping = false
          
          // 根据消息内容决定是否推荐内容
          if (userMessage.includes('推荐') || userMessage.includes('看什么')) {
            this.loadContentRecommendations();
          }
          
          // 滚动到底部
          this.$nextTick(() => {
            const messageList = document.querySelector('.message-list')
            if (messageList) {
              messageList.scrollTop = messageList.scrollHeight
            }
          })
        })
        .catch(error => {
          console.error('AI服务错误:', error);
          this.messages.push({
            sender: 'ai',
            text: '抱歉，我暂时无法提供回答，请稍后再试。'
          })
          this.isTyping = false
        })
    },
    handleQuickAction(action) {
      if (action === '去定制') {
        this.switchTab('customize')
      } else if (action === '去生成') {
        this.switchTab('generate')
      } else if (action === '返回主页') {
        this.$router.push('/')
      } else {
        // 将快捷操作作为用户消息发送
        this.messages.push({
          sender: 'user',
          text: action
        })
        
        // 使用AI服务处理快捷操作
        aiService.processMessage(action, {
          categories: this.selectedCategories,
          style: this.contentStyle,
          duration: this.videoDuration
        })
        .then(response => {
          this.messages.push({
            sender: 'ai',
            text: response
          })
          
          // 滚动到底部
          this.$nextTick(() => {
            const messageList = document.querySelector('.message-list')
            if (messageList) {
              messageList.scrollTop = messageList.scrollHeight
            }
          })
        })
        .catch(error => {
          console.error('AI服务错误:', error);
        })
      }
    },
    switchTab(tabId) {
      this.activeTab = tabId
      
      // 如果切换到推荐内容标签，加载推荐内容
      if (tabId === 'customize') {
        this.loadUserPreferences();
      }
    },
    loadUserPreferences() {
      // 从AI服务加载用户偏好
      const savedPreferences = aiService.getUserPreferences();
      if (savedPreferences) {
        this.selectedCategories = savedPreferences.categories || [];
        this.contentStyle = savedPreferences.style || '全部';
        this.videoDuration = savedPreferences.duration || '不限';
      }
    },
    saveUserPreferences() {
      aiService.saveUserPreferences({
        categories: this.selectedCategories,
        style: this.contentStyle,
        duration: this.videoDuration
      });
      this.showNotification('偏好设置已保存！');
    },
    applyPreferences() {
      this.saveUserPreferences();
      
      // 显示成功提示
      this.messages.push({
        sender: 'ai',
        text: `已应用你的内容偏好设置！\n\n兴趣类别：${this.selectedCategories.length > 0 ? this.selectedCategories.join('、') : '全部'}\n内容风格：${this.contentStyle}\n视频时长：${this.videoDuration}\n\n我会根据这些偏好为你推荐更符合你口味的内容。`
      })
      
      // 根据新偏好更新推荐内容
      this.loadContentRecommendations();
      
      // 切换回对话标签
      this.activeTab = 'chat'
      
      // 滚动到底部
      this.$nextTick(() => {
        const messageList = document.querySelector('.message-list')
        if (messageList) {
          messageList.scrollTop = messageList.scrollHeight
        }
      })
    },
    loadContentRecommendations() {
      this.isLoadingRecommendations = true;
      
      // 使用AI服务获取内容推荐
      aiService.getContentRecommendations({
        categories: this.selectedCategories,
        style: this.contentStyle,
        duration: this.videoDuration
      })
        .then(recommendations => {
          this.contentRecommendations = recommendations;
          this.isLoadingRecommendations = false;
        })
        .catch(error => {
          console.error('获取推荐内容错误:', error);
          this.isLoadingRecommendations = false;
        });
    },
    generateVideo() {
      if (!this.videoTopic.trim()) {
        this.showNotification('请输入视频主题');
        return;
      }
      
      this.isGenerating = true
      
      // 使用AI服务生成视频创意
      aiService.generateVideoIdea({
        topic: this.videoTopic,
        style: this.generatedVideoStyle,
        duration: this.videoLength,
        description: this.videoDescription,
        preferences: {
          categories: this.selectedCategories,
          style: this.contentStyle
        }
      })
      .then(result => {
        this.generatedVideoResult = {
          title: result.title,
          outline: result.outline,
          materials: result.materials,
          references: result.references
        }
        
        this.messages.push({
          sender: 'ai',
          text: `我已为你生成了关于"${this.videoTopic}"的视频创意！查看"视频生成"标签页获取详细内容。`
        })
        
        this.isGenerating = false
      })
      .catch(error => {
        console.error('生成视频创意错误:', error);
        this.messages.push({
          sender: 'ai',
          text: '抱歉，生成视频创意时遇到了问题，请稍后再试。'
        })
        this.isGenerating = false
      });
    },
    showNotification(message) {
      this.notification = message;
      setTimeout(() => {
        this.notification = null;
      }, 3000);
    }
  }
}
</script>

<style scoped>
/* AI智能体容器 */
.ai-agent-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
}

/* AI智能体悬浮按钮 */
.ai-agent-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fb7299, #e95989);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(251, 114, 153, 0.4);
  transition: all 0.3s ease;
  position: relative;
}

.ai-agent-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(251, 114, 153, 0.6);
}

/* 脉冲动画效果 */
.pulse-animation::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 50%;
  background: rgba(251, 114, 153, 0.6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

/* AI头像 */
.ai-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fb7299;
  position: relative;
  z-index: 1;
}

.ai-avatar.large {
  width: 40px;
  height: 40px;
}

/* AI智能体对话框 */
.ai-agent-dialog {
  width: 400px;
  max-height: 600px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 对话框头部 */
.dialog-header {
  padding: 16px;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  border-bottom: 1px solid #dee2e6;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-name {
  font-weight: 600;
  font-size: 16px;
  color: #333;
}

.dialog-controls {
  display: flex;
  gap: 8px;
}

.control-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #333;
}

.close-btn:hover {
  background: #fee;
  color: #ff4d4f;
}

/* 对话框内容区域 */
.dialog-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* 欢迎消息 */
.welcome-message {
  text-align: center;
  padding: 20px 0;
}

.welcome-message p {
  margin-bottom: 12px;
  color: #333;
}

.welcome-message .hint {
  font-size: 14px;
  color: #666;
  margin-top: 20px;
}

.welcome-message ul {
  text-align: left;
  margin: 10px auto;
  max-width: 250px;
}

.welcome-message li {
  margin-bottom: 6px;
  color: #666;
  font-size: 14px;
}

/* 消息列表 */
.message-list {
  flex: 1;
  overflow-y: auto;
  margin-bottom: 16px;
}

.message-item {
  display: flex;
  margin-bottom: 16px;
  gap: 12px;
}

.user-message {
  flex-direction: row-reverse;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e9ecef;
  flex-shrink: 0;
}

.message-content {
  max-width: 70%;
  padding: 12px;
  border-radius: 16px;
  word-wrap: break-word;
}

.user-message .message-content {
  background: linear-gradient(135deg, #fb7299, #e95989);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-content {
  background: #f8f9fa;
  color: #333;
  border-bottom-left-radius: 4px;
}

/* 快捷操作按钮 */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.quick-action-btn {
  padding: 6px 12px;
  border: 1px solid #dee2e6;
  background: white;
  border-radius: 16px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quick-action-btn:hover {
  background: #f8f9fa;
  border-color: #adb5bd;
}

/* 功能标签页 */
.feature-tabs {
  display: flex;
  border-bottom: 1px solid #dee2e6;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  color: #666;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: #f8f9fa;
  color: #333;
}

.tab-btn.active {
  color: #fb7299;
  border-bottom: 2px solid #fb7299;
}

/* 功能面板 */
.feature-panel {
  overflow-y: auto;
  padding-bottom: 16px;
}

/* 通用表单样式 */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #333;
  font-size: 14px;
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s ease;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #fb7299;
}

.form-group textarea {
  resize: vertical;
}

.form-group input[type="range"] {
  width: 100%;
}

/* 标签选择容器 */
.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-checkbox {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid #dee2e6;
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
}

.tag-checkbox:hover {
  background: #f8f9fa;
}

.tag-checkbox input[type="checkbox"] {
  display: none;
}

.tag-checkbox input[type="checkbox"]:checked + .tag-name {
  color: #fb7299;
}

.tag-checkbox input[type="checkbox"]:checked {
  background: #fff5f7;
  border-color: #fb7299;
}

/* 通知提示样式 */
.ai-notification {
  position: fixed;
  bottom: 80px;
  right: 20px;
  background: linear-gradient(135deg, #fb7299, #e95989);
  color: white;
  padding: 12px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(251, 114, 153, 0.3);
  font-size: 14px;
  z-index: 1001;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 打字状态指示器 */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 推荐内容样式 */
.recommendations-preview {
  margin-top: 20px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
}

.recommendations-preview h5 {
  margin-bottom: 12px;
  color: #333;
  font-size: 14px;
}

.recommendation-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recommendation-item {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.recommendation-item:hover {
  background: #fff5f7;
  transform: translateX(2px);
}

.rec-thumbnail {
  width: 60px;
  height: 40px;
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
  border-radius: 4px;
  flex-shrink: 0;
}

.rec-info {
  flex: 1;
  min-width: 0;
}

.rec-title {
  font-size: 12px;
  color: #333;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rec-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: #999;
}

.view-more-btn {
  margin-top: 12px;
  width: 100%;
  padding: 6px;
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 12px;
  color: #fb7299;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-more-btn:hover {
  background: #fff5f7;
  border-color: #fb7299;
}

/* 内容定制页面的推荐内容样式 */
.recommendations-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.recommendations-section h5 {
  margin-bottom: 12px;
  color: #333;
  font-size: 14px;
}

.no-recommendations {
  text-align: center;
  padding: 20px;
  color: #999;
  font-size: 13px;
}

/* 加载状态样式 */
.loading-recommendations {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  gap: 10px;
  color: #999;
  font-size: 13px;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #fb7299;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 按钮样式 */
.apply-btn,
.generate-btn {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: linear-gradient(135deg, #fb7299, #e95989);
  color: white;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.apply-btn:hover,
.generate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(251, 114, 153, 0.3);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 清除结果按钮 */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.clear-result-btn {
  background: none;
  border: none;
  color: #999;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.clear-result-btn:hover {
  background: #f8f9fa;
  color: #666;
}

/* 生成结果样式 */
.generate-result {
  margin-top: 20px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
}

.generate-result h5 {
  margin-bottom: 12px;
  color: #333;
}

.result-content p {
  margin-bottom: 8px;
  font-size: 14px;
}

.result-content ul {
  margin: 8px 0 12px 20px;
}

.result-content li {
  margin-bottom: 4px;
  font-size: 14px;
}

.reference-videos {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.reference-video-item {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.reference-video-item:hover {
  background: #fff5f7;
}

.video-thumbnail {
  width: 60px;
  height: 40px;
  background: #e9ecef;
  border-radius: 4px;
  flex-shrink: 0;
}

.video-info {
  flex: 1;
  min-width: 0;
}

.video-title {
  font-size: 12px;
  color: #333;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.video-author {
  font-size: 11px;
  color: #999;
}

/* 对话框输入区域 */
.dialog-input {
  padding: 16px;
  border-top: 1px solid #dee2e6;
  display: flex;
  gap: 8px;
}

.dialog-input input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #dee2e6;
  border-radius: 20px;
  font-size: 14px;
  transition: border-color 0.2s ease;
}

.dialog-input input:focus {
  outline: none;
  border-color: #fb7299;
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #fb7299, #e95989);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .ai-agent-dialog {
    width: 90vw;
    max-height: 70vh;
  }
  
  .message-content {
    max-width: 80%;
  }
}
</style>